#include <opencv/cv.h>
#include <opencv/highgui.h>
#include <stdio.h>  

// A Simple Camera Capture Framework 

int main() 
{    
  CvCapture* capture = cvCaptureFromCAM(0);   
  if( !capture ) 
  {    
    fprintf( stderr, "ERROR: capture is NULL \n" );     
    getchar();     
    return -1;   
  }    

  cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH, 1600);
  cvSetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT, 1200);
  
  // Get one frame     
  IplImage* frame = cvQueryFrame( capture );     
  printf("image size: %d X %d\n", frame->width, frame->height);
  if( !frame ) 
  {       
    fprintf( stderr, "ERROR: frame is null...\n" );       
    getchar();       
    return -1; 
  }
  
  if (!cvSaveImage("image_src.jpg", frame))
  {
    fprintf(stderr, "ERROR: unable to save image\n");
    return -1;
  }
 
  cvReleaseCapture( &capture );   
  return 0; 
}    
